﻿using FineAdmin.Common;
using FineAdmin.IService;
using FineAdmin.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Schema;

namespace HuiJi.CMS.Blog.Controllers
{
    public class CommentsController : BaseController
    {
        // GET: Comments
        public IBlogCommentService BlogCommentService { get; set; }
        public ActionResult Index(int p = 1)
        {
            ViewBag.Active = "Comments";
            int total;
            ViewBag.BlogCommentList = BlogCommentService.GetList(new BlogCommentModel() { Type = 2 }, new PageInfo() { page = p, limit = 10 }, out total);
            ViewBag.Total = total;
            ViewBag.Page = p;
            return View();
        }

        public ActionResult AddComment(BlogCommentModel model, string captcha)
        {
            if (Session["session_verifycode_type3"].IsEmpty() || Md5.md5(captcha.ToLower(), 16) != Session["session_verifycode_type3"].ToString())
            {
                return Json(SuccessTip("留言失败，验证码不正确"), JsonRequestBehavior.DenyGet);
            }
            if (string.IsNullOrWhiteSpace(model.NickName))
            {
                model.NickName = "热心网友";
            }
            model.IP = Net.Ip;
            model.City = Net.GetLocation(Net.Ip);
            model.State = 2;
            model.Type = 2;
            model.CreateTime = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            model.UpdateUserId = 1;
            model.CreateUserId = 1;
            BlogCommentService.Insert(model);
            return Json(SuccessTip("留言成功，审核后将会显示"), JsonRequestBehavior.DenyGet);
        }

        public ActionResult GetSubmitCode()
        {
            return File(new VerifyCode().GetVerifyCode(type: 3), @"image/Gif");
        }
    }
}